package com.ndp.fb.rdb;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.springframework.context.ApplicationContext;

import com.alibaba.dubbo.container.Main;
import com.alibaba.fastjson.JSON;
import com.ndp.fb.cache.redis.RedisClientImpl;
import com.ndp.fb.config.BaseConfig;
import com.ndp.fb.config.XmlBaseConfig;
import com.ndp.fb.dubbo.container.ContainerPost;
import com.ndp.fb.dubbo.container.SpringBootContainer;
import com.ndp.fb.rdb.api.AdwordRdbService;
import com.ndp.fb.rdb.api.EntrustAccountRdbService;
import com.ndp.fb.rdb.model.Adword;
import com.ndp.fb.rdb.model.EntrustAccount;
import com.ndp.fb.redis.api.RedisClient;
import com.ndp.fb.redis.model.RedisParams;

/**
 * Created by hunk.qin on 2015/1/26.
 */
public class RdbRunMain {

    public static void main(String[] args) {
//        test();
        BaseConfig.DEV = true;
        XmlBaseConfig.LoadXmlConfig = false;
        SpringBootContainer.containerPostList.add(new ContainerPost() {
            @Override
            public void doPost(ApplicationContext applicationContext) {
            	AdwordRdbService adwordRdbService = applicationContext.getBean(AdwordRdbService.class);
            	List<String> lan = new ArrayList<>();
            	lan.add("English");
            	lan.add("Chinese");
            	Adword adword = adwordRdbService.findRandomForRobot(998L, 5868243213818L, lan);
            	System.out.println(adword.getWord());
//                EntrustAccountRdbService entrustAccountRdbService = applicationContext.getBean(EntrustAccountRdbService.class);
//                List<EntrustAccount> s = entrustAccountRdbService.findAdAccountListByRoles("ADMIN");
//                System.out.println(s.size());
            }
        });
        String[] argsparams = {"springbootweb"};
        Main.main(argsparams);
        System.out.print("start rdb down");
    }


    private static void doinfiRedis(ApplicationContext applicationContext) {
        RedisClient redisClient = applicationContext.getBean(RedisClientImpl.class);

        String keys = "aaaaaaaaaaaaaaaa";
        for (int i = 0; i < 100; i++) {
            RedisParams redisParams = new RedisParams();
            redisParams.setAccountId("1390685454498661");
            redisParams.setContext(new byte[100]);
            redisParams.setFileName("D://fda.txt");
            Double aDouble = Double.valueOf(i + "");
            redisParams.setScore(aDouble);
            redisClient.zadd(keys, aDouble, redisParams);
        }
        Set<Object> objects = redisClient.zPopByScore(keys, 0D, 2D, 0L, 100L);
        System.out.println(JSON.toJSONString(objects));

    }

    private static void test(){
        /*EcAdSetActionRecord s = ReflectUtil.getMockInstance(EcAdSetActionRecord.class);
        s.setStrategy("{}");
        s.setFbDailySnap("{}");
        s.setGaDailySnap("{}");
        s.setFbLifeSnap("{}");
        s.setGaLifeSnap("{}");

        List<EcAdSetActionRecord> adSets = new ArrayList<>();
        adSets.add(s);

        EcMarketingActionRecord m= ReflectUtil.getMockInstance(EcMarketingActionRecord.class);
        m.setAdSets(adSets);
        m.setUser(ReflectUtil.getMockInstance(User.class));
        String x = JSON.toJSONString(m);
        System.out.println(x);*/
    }

}
